//
//  MineViewController.m
//  ZJControlsClass
//
//  Created by apple on 2024/10/22.
//

#import "MineViewController.h"
#import "MineTableViewCell.h"
#import "MineHeadView.h"


#import "ViewController.h"
#import "AppDelegate.h"

#import "ZJMineThroughRecordViewController.h"
#import "ZJMineApplicationRecordViewController.h"
#import "ChangePasswordViewController.h"
#import "ZJMineApplicationOneViewController.h"
#import "ZJMessagePunishViewController.h"
#import "HomeOnlineExaminationViewController.h"

#import "testViewController.h"


@interface MineViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray * dataSource;
@property (nonatomic,strong) MineHeadView * headView;

@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的";
    
    self.view.backgroundColor = COLOR_RGB(229, 242, 255);
    
//    self.dataSource = [NSMutableArray arrayWithObjects:@"申请记录",@"通行记录",@"违规记录",@"携带工具",@"入场货物",@"考试成绩",@"违规举报",@"帮助解答",@"意见建议",@"当前版本", nil];
    self.dataSource = [NSMutableArray arrayWithObjects:@"申请记录",@"通行记录",@"考试成绩",@"修改密码",@"当前版本", nil];
    
    
    [self setUpUI];
    
}

-(void)setUpUI{
    
    [self.view addSubview:self.tableView];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(StatusBarHeight - 4);
        make.left.bottom.right.equalTo(self.view);
    }];
    
    
    
}


#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MineTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell"];
    if (!cell){
        cell = [[MineTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"MineTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.msgLabel.text = self.dataSource[indexPath.row];
    cell.img.image = [UIImage imageNamed:self.dataSource[indexPath.row]];
    
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *titleStr = self.dataSource[indexPath.row];

    if ([titleStr isEqualToString: @"通行记录"]) {
        ZJMineThroughRecordViewController * vc = [ZJMineThroughRecordViewController new];
        vc.hidesBottomBarWhenPushed = false;
        [[SaViewControllerUtils currentViewController].navigationController pushViewController:vc animated:YES];
    
    }else if ([titleStr isEqualToString: @"申请记录"]) {
        ZJMineApplicationRecordViewController * vc = [ZJMineApplicationRecordViewController new];
        vc.hidesBottomBarWhenPushed = false;
        [[SaViewControllerUtils currentViewController].navigationController pushViewController:vc animated:YES];
    
    }else if ([titleStr isEqualToString:@"违规记录"]){
        
        ZJMessagePunishViewController * vc = [ZJMessagePunishViewController new];
        vc.hidesBottomBarWhenPushed = false;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if ([titleStr isEqualToString:@"考试成绩"]){
        HomeOnlineExaminationViewController *vc = [HomeOnlineExaminationViewController new];
        vc.hidesBottomBarWhenPushed = false;
        [[SaViewControllerUtils currentViewController].navigationController pushViewController:vc animated:YES];
        // 延迟一帧执行，确保视图加载完成
        dispatch_async(dispatch_get_main_queue(), ^{
            [vc collectionViewClickIndex:2]; // 2代表"已结束考试"标签的索引
        });
    }else if ([titleStr isEqualToString:@"修改密码"]){
        ChangePasswordViewController * vc = [ChangePasswordViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        ViewController *loginVC = [ViewController new];
        loginVC.hidesBottomBarWhenPushed = YES;
    
        [self.navigationController pushViewController:loginVC animated:YES];
        NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@(0) forKey:@"isLogin"];
        
//        testViewController * vc = [testViewController new];
//        [self.navigationController pushViewController:vc animated:YES];
        
        
    }
       
    //    [[AppDelegate shareInstance] application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:nil];
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ALIGN_HEIGHT_PT(50);
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    self.headView = [[MineHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ALIGN_HEIGHT_PT(250)- StatusBarHeight)];
    self.headView.backgroundColor = [UIColor clearColor];
    
    return self.headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return ALIGN_HEIGHT_PT(250) - StatusBarHeight;
}


-(UITableView *)tableView{
    if (!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = COLOR_RGB(229, 242, 255);

    }
    return _tableView;
}




@end
